<?php

/**
 * @author shadow245
 * @copyright 2013
 */

class Bootstrap {
    
    public static function run(Request $peticion){
        $module = $peticion->getModule();
        $controller = $peticion->getControlador() . "Controller";
        $rutaController = ROOT . $module . DS . 'controllers' . DS . $controller . '.php';
        
        $metodo = $peticion->getMetodo();
        $args = $peticion->getArgs();

        if(is_readable($rutaController)){
            require_once $rutaController;
            
            $controller = new $controller();
            $controller->setModule($module);
            if(is_callable(array($controller, $metodo))){
                $metodo = $peticion->getMetodo();
            }else{
                $metodo = DEFAULT_METHOD;
            }
            
            if(isset($args)){
                call_user_func_array(array($controller, $metodo), $peticion->getArgs());
            }else{
                call_user_func(array($controller,$metodo));
            }
        }else{
            throw new Exception('4041');
        }
    }
}
?>